package com.aoxin.controller.course.webCourse;

import com.aoxin.model.SlfMakeupCourse;
import com.aoxin.service.inter.course.webCourse.MakeupCourseService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.EmptyUtil;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/web/mkeupCourse/")
public class MakeupCourseController {

	@Autowired
	MakeupCourseService makeupCourseService;

	/**
	 * 新增补课信息
	 * 
	 * @param slfMakeupCourse
	 * @param res
	 * @return
	 */
	@RequestMapping("insertMakeupCourse")
	@LogInfo(content = "补课信息", operateType = OperateType.INSERT)
	public AjaxRes insertMakeupCourse(SlfMakeupCourse slfMakeupCourse, AjaxRes res) {
		try {
			if (!EmptyUtil.objFieldsIsEmpty(slfMakeupCourse)) {
				Integer result = makeupCourseService.insertMakeupCourse(slfMakeupCourse);
				if (result != 0) {
					res.setSucceedMsg("insertMakeupCourse success!");
				} else {
					res.setFailMsg("insertMakeupCourse Fail!");
				}
			} else {
				res.setFailMsg("slfMakeupCourse is null");
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return res;
	}

	/**
	 * 批量删除补课信息
	 * 
	 * @param myCoursePageIds
	 * @param res
	 * @return
	 */
	@RequestMapping("deleteMakeupCourse")
	@LogInfo(content = "补课信息", operateType = OperateType.DELETE)
	public AjaxRes deleteMakeupCourse(@RequestParam("myCoursePageIds") List<Integer> myCoursePageIds, AjaxRes res) {
		if (myCoursePageIds != null && myCoursePageIds.size() > 0) {
			Integer result = makeupCourseService.deleteMakeupCourse(myCoursePageIds);
			if (result != 0) {
				res.setSucceedMsg("deleteMakeupCourse success!");
			} else {
				res.setFailMsg("deleteMakeupCourse Fail!");
			}
		} else {
			res.setFailMsg("myCoursePageIds is null");
		}
		return res;
	}

	/**
	 * 查询补课信息
	 * 
	 * @param slfMakeupCourse
	 * @param res
	 * @param pageInfo
	 * @return
	 */
	@RequestMapping("getMakeupCourse")
	@LogInfo(content = "补课信息", operateType = OperateType.QUERY)
	public AjaxRes getMakeupCourse(SlfMakeupCourse slfMakeupCourse, AjaxRes res) {
		try {
			List<SlfMakeupCourse> slfMakeupCoursePageInfo = makeupCourseService.getMakeupCorse(slfMakeupCourse);
			res.setSucceed(slfMakeupCoursePageInfo, Const.DATA_SUCCEED);
		} catch (Exception e) {
			res.setFailMsg(e.getMessage());
		}
		return res;
	}

	/**
	 * 修改补课信息
	 * 
	 * @param slfMakeupCourse
	 * @param res
	 * @return
	 */
	@RequestMapping("updateMakeupCourse")
	@LogInfo(content = "补课信息", operateType = OperateType.UPDATE)
	public AjaxRes updateMakeupCourse(SlfMakeupCourse slfMakeupCourse, AjaxRes res) {
		try {
			if (!EmptyUtil.objFieldsIsEmpty(slfMakeupCourse)) {
				Integer result = makeupCourseService.updateMakeupCourse(slfMakeupCourse);
				if (result != 0) {
					res.setSucceedMsg("updateMakeupCourse success!");
				} else {
					res.setFailMsg("updateMakeupCourse Fail!");
				}
			} else {
				res.setFailMsg("slfMakeupCourse is null");
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return res;
	}

}
